import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
import { OVERLAY_KEY, EQUIPMENT_CODE, MapDataService } from '../service/map-data.service';
import * as moment from 'moment';
import { SELECT_OPTIONS } from 'app/app.constants';
import { PublicService } from 'app/public/public.service';
import { VmsSetComponent } from 'app/public/vms-set/vms-set.component';

@Component({
    selector: 'itmp-equipment-overlay',
    templateUrl: './equipment-overlay.component.html',
    styleUrls: ['./equipment-overlay.component.css']
})
export class EquipmentOverlayComponent implements OnInit {
    @Input() featureData = null;
    @Output() visibleChange = new EventEmitter<OVERLAY_KEY>();
    @ViewChild(VmsSetComponent) vms: VmsSetComponent;
    EQUIPMENT_CODE = EQUIPMENT_CODE;
    overlayKey = OVERLAY_KEY.EQUIPMENT_OVERLAY;
    moment = moment;
    eqtDetail: any = {};
    vmsgetData = {
        illumMode: null,
        illumLevel: null,
        illumNumLevels: null
    };
    controlMode = {
        '0': 'Isolated',
        '1': 'Flexilink',
        '2': 'Master-Isolated',
        '3': 'Full Masterlink'
    };
    congestion = {
        0: '',
        1: ''
    };
    constructor(private pub: PublicService, private mapDataService: MapDataService) {}

    close() {
        this.visibleChange.emit(this.overlayKey);
    }
    ngOnInit() {
        if (this.featureData && this.featureData.eqtType === EQUIPMENT_CODE.TSC) {
            this.mapDataService.getScatsData(this.featureData.eqtId).subscribe(e => {
                this.eqtDetail = {};
                if (e.messagecode === '000000') {
                    this.eqtDetail = e.data;
                }
            });
        }
    }
    // 初始化数据
    initData(data) {
        this.vmsgetData.illumMode = data && '' + data.illumMode;
        this.vmsgetData.illumLevel = data && data.illumLevel;
        this.vmsgetData.illumNumLevels = data && data.illumNumLevels;
    }
    // 确定按钮
    handleOk() {
        this.vms.handleOk(this.vmsgetData).subscribe(res => {
            if (res) {
                this.visibleChange.emit(this.overlayKey);
            }
        });
    }
}
